package com.momo.hr.controller;

import com.momo.hr.bean.RespBean;
import com.momo.hr.controller.config.VerificationCode;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.image.BufferedImage;
import java.io.IOException;

@RestController
public class LoginController {

    @GetMapping("/login")
    public RespBean login(){
        return RespBean.error("请登录");
    }

    /**
     * 生成验证码的Controller
     * @param httpSession 把需要的验证码存入到session中去
     * @param response 使用response的输出流把验证码图片写出去
     * @throws IOException
     */
    @GetMapping("/verifyCode")
    public void verifyCode(HttpSession httpSession, HttpServletResponse response) throws IOException {
        VerificationCode verificationCode = new VerificationCode();
        BufferedImage image = verificationCode.getImage();//生成图片
        String text = verificationCode.getText();//生成文本信息
        httpSession.setAttribute("verify_code",text);//设置验证码
        VerificationCode.output(image,response.getOutputStream());//
    }
}


